package com.nuoyuan.wx.common.controller;

import com.nuoyuan.wx.common.utils.GsonUtil;
import com.nuoyuan.wx.common.utils.HashUtil;
import lombok.Data;

import javax.servlet.http.HttpServletRequest;

/**
 * @Package com.nuoyuan.wx.admin.controller
 * @ClassName BaseController
 * @Description TODO
 * @Author linus
 * @Date 2020-02-13 14:48
 * @Version 1.0
 **/
public class BaseController {

    private static final String salt = "plmokn!@#$";

    public String buildErrorResp(String msg) {
        return GsonUtil.toJson(new ResponseVo(null, msg));
    }

    public String buildSimpleSuccResp() {
        return GsonUtil.toJson(new ResponseVo());
    }

    public String buildToken(String key, String value) {
        return HashUtil.SHA1(key + value + salt);
    }

    public String getToken(HttpServletRequest request) {
        return request.getHeader("token");
    }

    @Data
    class ResponseVo {
        private String code;
        private String msg;

        ResponseVo() {
        }

        ResponseVo(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }
    }
}
